import numpy as np

def findmaxmin(dst):
    dst = np.squeeze(dst)
    dst.reshape(4, 2)
    print(dst.shape)
    x_list = np.array([pt[0] for pt in dst])
    x_max = np.max(x_list)
    x_min = np.min(x_list)
    y_list = np.array([pt[1] for pt in dst])
    y_max = np.max(y_list)
    y_min = np.min(y_list)
    print("the maximum minimum is: {}, {}, {}, {}".format(x_max, x_min, y_max, y_min))
    return x_max, x_min, y_max, y_min

def findNextRIO(RIOBox, sizePic, n = 2):
    nxt_x_min = np.int32(RIOBox[1] - (RIOBox[0] - RIOBox[1]) * (n-1)/2)
    nxt_x_min = nxt_x_min if nxt_x_min > 0 else 0
    nxt_x_max = np.int32(RIOBox[0] + (RIOBox[0] - RIOBox[1]) * (n-1)/2)
    nxt_x_max = nxt_x_max if nxt_x_max < sizePic[0] else sizePic[0]
    nxt_y_min = np.int32(RIOBox[3] - (RIOBox[2] - RIOBox[3]) * (n-1)/2)
    nxt_y_min = nxt_y_min if nxt_y_min > 0 else 0
    nxt_y_max = np.int32(RIOBox[2] + (RIOBox[2] - RIOBox[3]) * (n-1)/2)
    nxt_y_max = nxt_y_max if nxt_y_max < sizePic[1] else sizePic[1]
    return [nxt_x_max, nxt_x_min, nxt_y_max, nxt_y_min]

def ReturnToOrg(OriginPoint, pt, ratio):
    return [OriginPoint[0] + np.int32(pt[0]/ratio), OriginPoint[1] + np.int32(pt[1]/ratio)]

def PicToPlan(Picpt, PicSize):
    return [Picpt[0], PicSize[1] -Picpt[1]]
    
def PlanToPic(Planpt, PicSize):
    return [Planpt[0], PicSize[1] -Planpt[1]]

def MoveAlongZ(x, y):
    return [int(x*4/5+90), int(y+230)]

def PicAngleToPlanAngle(angle):
    return 360-(angle + 45)%360